<?php

namespace App\Http\Controllers;

use App\Http\Requests\FsUserPhoneRequest;
use App\Models\FsUserPhone;
use App\Transformers\FsUserPhoneTransformer;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;


class FsUserPhoneController extends Controller
{
    /**
     * @api {post} /api/fsUser/phone?include=user,FsUser 会员手机标记添加
     * @apiGroup FsUserPhoneRemark
     *
     * @apiHeader {String} Authorization Bearer+空格+access_token [必填]
     * @apiHeader {String} Accept application/vnd.operationsystem.v1+json [必填]
     * @apiHeader {String} Content-Type application/json [必填]
     *
     * @apiParam {String} status  枚举 成功回访、停机、关机、空号、无人接听、直接挂掉、用户正忙、不在服务区
     *
     * @apiParam {int} fs_user_id 会员id
     *
     * @apiVersion 1.0.0
     * @apiSuccessExample {json} Success-Response:
     *       HTTP/1.1 201 OK
     */
    public function store(FsUserPhoneRequest $request, FsUserPhone $fsUserPhone){
        $data = $request->all();
        $data['user_id'] = Auth::User()->id;
        $res = $fsUserPhone->create($data);

        return $this->response->item($res, new FsUserPhoneTransformer('user'));
    }

    public function update(FsUserPhoneRequest $request, FsUserPhone $fsUserPhone){

    }

    /**
     * @api {get} /api/fsUser/phone?include=user,fsUser 会员手机标记列表
     * @apiGroup FsUserPhoneRemark
     *
     * @apiHeader {String} Authorization Bearer+空格+access_token [必填]
     * @apiHeader {String} Accept application/vnd.operationsystem.v1+json [必填]
     * @apiHeader {String} Content-Type application/json [必填]
     *
     * @apiParam {int} fs_user_id 会员id
     *
     * @apiVersion 1.0.0
     * @apiSuccessExample {json} Success-Response:
     *       HTTP/1.1 200 OK
     *       {
     *           "data": [
     *               {
     *                   "id": 1,
     *                   "status": "用户正忙",
     *                   "user": "admin",
     *                   "created_at": "2019-01-02 16:43:03",
     *                   "updated_at": "2019-01-02 16:43:03"
     *               }
     *           ]
     *       }
     */
    public function index(Request $request, FsUserPhone $fsUserPhone){
        $data = $request->validate([
            'fs_user_id'=>'required|exists:mysql_branch.fs_user,id'
        ]);

        $data = $fsUserPhone->where('fs_user_id',$data['fs_user_id'])->orderBy('created_at','DESC')->get();

        return $this->response->collection($data, new FsUserPhoneTransformer());
    }
}
